package com.wyl.hw;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable, Text,IntWritable, IntWritable> {

    IntWritable word = new IntWritable();
    IntWritable one = new IntWritable(1);
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            //1.此处将Text类型转换为Integer主要是想直接利用IntegerWriteable 实现的compareTo(IntWritable o)方法来排序
            word.set(Integer.parseInt(value.toString()));
            context.write(word, one);
    }
}
